<template>
    <div>
        <h1>康复理疗添加</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>项目名称</td>
                    <td>
                        <input type="text" v-model="emp.Mingcheng">
                    </td>
                </tr>
                <tr>
                    <td>项目编码</td>
                    <td>
                        <input type="text" v-model="emp.Bianma" disabled>
                    </td>
                </tr>
                <tr>
                    <td>佣金</td>
                    <td>
                        <input type="text" v-model="emp.Yongjin">
                    </td>
                </tr>
                <tr>
                    <td>服务人数</td>
                    <td>
                        <input type="text" v-model="emp.Renshu">
                    </td>
                </tr>
                <tr>
                    <td> 服务时长</td>
                    <td>
                        <input type="text" v-model="emp.Shichang">
                    </td>
                </tr>
                <tr>
                    <td>项目说明</td>
                    <td>
                        <textarea cols="50" role="5" v-model="emp.Shuoming"></textarea>
                    </td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" name="Zhuangtai" :value="true" v-model="emp.Zhuangtai">启用
                        <input type="radio" name="Zhuangtai" :value="false" v-model="emp.Zhuangtai">禁用
                    </td>
                </tr>
            
                <tr>
                    <td></td>
                    <td>
                        <button class="btn btn-success" @click="add">添加</button>
                    </td>
                </tr>
            </tbody>
        </table>

    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted } from 'vue';
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
import moment from 'moment';

const router=useRouter();
const route=useRoute();


let emp:any=reactive({
  "Mingcheng": "",
  "Bianma":moment(new Date).format("YYYYMMDD")+Math.random().toString().substring(3,6),
  "Yongjin": '',
  "Renshu": '',
  "Shichang": "",
  Zhuangtai:true,
  "Shuoming": "",
})



//添加
const add=()=>{
    console.log(emp);

    if(emp.Mingcheng==''){
        alert('项目名称不能为空')
        return;
    }
    if(emp.Yongjin==''){
        alert('佣金不能为空')
        return;
    }
    if(emp.Renshu==''){
        alert('服务人数不能为空')
        return;
    }
    if(emp.Renshu>10){
        alert('服务人数必须是整数')
        return;
    }
    if(emp.Shichang==''){
        alert('时长不能为空')
        return;
    }
    if(emp.Shichang>24){
        alert('时长必须是整数')
        return;
    }

    axios({
        url:'/api/House/AddEmp',
        method:'post',
        data:emp
    }).then(res=>{
        console.log(res);
        if(res.data>0){
            alert('添加成功')
            router.push('/houseList')
            return;
        }else if(res.data==-1){
            alert('项目名称已存在')
            return;
        }
        else{
            alert('添加失败')
            return;
        }
        
    }).catch(err=>{
        console.log(err);
        
    })
    
}

</script>

<style scoped>

</style>